define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'tender/index',
                    add_url: 'tender/add',
                    edit_url: 'tender/edit',
                    del_url: 'tender/del',
                    multi_url: 'tender/multi',
                    table: 'borrow_tender',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'tenderId',
                sortName: 'tenderId',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'tenderId', title: __('id'),operate:false},
                        {field: 'user.phone', title: __('Phone')},
                        {field: 'user.name', title: __('Name'),operate:false},
                        {field: 'borrow.name', title: __('Borrowname')},
                        {field: 'borrow.aprTotal', title: __('Aprs'),operate:false},
                        {field: 'borrowtime', title: __('Borrowtime'),operate:false},
                        {field: 'account', title: __('Account'),operate:false},
                        {field: 'interest', title: __('Interest'),operate:false},
                        {field: 'cardType', title: __('CardType'),operate:false},
                        {field: 'cardshouyi', title: __('Cardshouyi'),operate:false},
                        {field: 'totalmoney', title: __('Totalmoney'),operate:false},
                        //{field: 'addApr', title: __('AddApr')},
                        //{field: 'redMoney', title: __('RedMoney')},
                        //{field: 'addInterest', title: __('AddInterest')},
                        //{field: 'totalAccount', title: __('TotalAccount')},
                        //{field: 'repayAccount', title: __('RepayAccount')},
                        {field: 'status', title: __('Status'), formatter: Controller.api.formatter.status,operate:false},
                        {field: 'createTime', title: __('CreateTime'), formatter: Table.api.formatter.datetime,operate: 'BETWEEN', type: 'datetime', addclass: 'datetimepicker', data: 'data-date-format="YYYY-MM-DD HH:mm:ss"'},
                        {field: 'borrow.fullTime', title: __('FullTime'), formatter: Table.api.formatter.datetime,operate:false},
                        //{field: 'updateTime', title: __('UpdateTime'), formatter: Table.api.formatter.datetime},
                        //{field: 'authCode', title: __('AuthCode')},
                        //{field: 'cardId', title: __('CardId')},
                        //{field: 'repayAddInterest', title: __('RepayAddInterest')},
                        //{field: 'isFirst', title: __('IsFirst')},
                        {field: 'isFirst', title: __('IsFirst'),formatter: Controller.api.formatter.isFirst,searchList: {"0": "否", "1": "是"}},
                        {field: 'device', title: __('Device'),operate:false},
                        //{field: 'operate', title: __('Operate'), events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            formatter:{
                status:function(value,row,index){

                    switch(value){
                        case 0 : var ccc= '无效';break;
                        case 1 : var ccc= '投标成功';break;
                        case 2 : var ccc= '开始计息';break;
                        case 3 : var ccc= '放款成功';break;
                        case 4 : var ccc= '还款成功';break;
                        default : var ccc= '';
                    }
                    return ccc;
                },
                isFirst :function(value,row,index){
                    if(value==1){
                        return '是';
                    }else{
                        return '否';
                    }
                }
            }
        }
    };
    return Controller;
});